<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="Jsp.User" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/11
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Jstl</title>
</head>
<body>

    <%
        List<String> list=new ArrayList<String>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        request.setAttribute("list",list);

        List<String> list1=new ArrayList<String>();
        request.setAttribute("list1",list1);

        request.setAttribute("number",4);

    %>
<h2>if标签</h2>
<%--判断list是否为空，若不为空展示list
 从域对象取出list--%>
<c:if test="${not empty list}">
    ${list} <br>
    ${list[0]}<br>
    ${list[1]}<br>
    ${list[2]}<br>
</c:if>
<c:if test="${empty list1}">
    null
</c:if>

<c:if test="${number%2==0}">
    ${number是偶数}
</c:if>
<c:if test="${number%2!=0}">
    ${number不是偶数}
</c:if>
    <br>
<h2>foreach标签</h2>

<c:forEach begin="0" end="5" var="i" step="2" varStatus="s">
    ${i}<br>
    ${s.index}
    ${s.count}
</c:forEach>


<%
    User u1=new User("张三",18,new Date());
    User u2=new User("lili",17,new Date());
    User u3=new User("tom",19,new Date());
    List<User> userList=new ArrayList<User>();

    userList.add(u1);
    userList.add(u2);
    userList.add(u3);
    request.setAttribute("userList",userList);
%>



    <c:forEach items="${userList}" var="u" varStatus="s">
        ${u}<br>
        ${u.name}<br>
        ${s.index}<br>
        ${s.count}<br>
    </c:forEach>




</body>
</html>
